package com.lolaage.tracks;

import com.baidu.mapapi.CoordinateConvert;
import com.baidu.mapapi.GeoPoint;

import android.location.Location;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-9-10
 * @see : 轨迹节点
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class TrackPoint
{
    
    public long _id;
    public long trackId;
    public double latitude;
    public double longitude;
    public double altitude;
    public float  speed;
    public long   time;
    
    public static TrackPoint toTrackPoint(Location location)
    {
        TrackPoint cacheObject = new TrackPoint();
        cacheObject.latitude = location.getLatitude();
        cacheObject.longitude = location.getLongitude();
        cacheObject.altitude = location.getAltitude();
        cacheObject.speed = location.getSpeed();
        cacheObject.time = location.getTime();
        return cacheObject;
    }

    /** 获取真实的位置*/
    public Location toLocation()
    {
        Location loc = new Location("point");
        loc.setLatitude(latitude);
        loc.setLongitude(longitude);
        loc.setAltitude(altitude);
        loc.setSpeed(speed);
        loc.setTime(time);
        return loc;
    }
    
    /** 获取地图上的正确显示的坐标*/
    public GeoPoint toGeoPoint()
    {
        if(latitude > 0 && longitude > 0)
        {
            // 有效的
            return CoordinateConvert.bundleDecode(
                    CoordinateConvert.fromWgs84ToBaidu(
                            new GeoPoint((int) (latitude * 1E6),
                            (int) (longitude * 1E6))));
        }else
        {
            // 非法的
            return new GeoPoint(0,0);
        }
    }
}